package com.ruoyi.bizsys.controller;

import java.util.List;

import com.ruoyi.bizsys.vo.LoanIouDeferredVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bizsys.domain.LoanIouDeferred;
import com.ruoyi.bizsys.service.ILoanIouDeferredService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 延期借据Controller
 *
 * @author ygw
 * @date 2022-08-09
 */
@RestController
@RequestMapping("/business/deferred")
public class LoanIouDeferredController extends BaseController {
    @Autowired
    private ILoanIouDeferredService loanIouDeferredService;

    /**
     * 查询延期借据列表
     */
    @PreAuthorize("@ss.hasPermi('business:deferred:list')")
    @GetMapping("/list")
    public TableDataInfo list(LoanIouDeferred loanIouDeferred) {
        startPage();
        List<LoanIouDeferredVo> list = loanIouDeferredService.selectLoanIouDeferredList(loanIouDeferred);
        return getDataTable(list);
    }

    /**
     * 导出延期借据列表
     */
    @PreAuthorize("@ss.hasPermi('business:deferred:export')")
    @Log(title = "延期借据", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LoanIouDeferred loanIouDeferred) {
        List<LoanIouDeferredVo> list = loanIouDeferredService.selectLoanIouDeferredList(loanIouDeferred);
        ExcelUtil<LoanIouDeferredVo> util = new ExcelUtil<LoanIouDeferredVo>(LoanIouDeferredVo.class);
        return util.exportExcel(list, "deferred");
    }

    /**
     * 获取延期借据详细信息
     */
    @PreAuthorize("@ss.hasPermi('bizsys:deferred:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(loanIouDeferredService.selectLoanIouDeferredById(id));
    }

    /**
     * 新增延期借据
     */
    @PreAuthorize("@ss.hasPermi('business:deferred:add')")
    @Log(title = "延期借据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LoanIouDeferred loanIouDeferred) {
        return toAjax(loanIouDeferredService.insertLoanIouDeferred(loanIouDeferred));
    }

    /**
     * 修改延期借据
     */
    @PreAuthorize("@ss.hasPermi('business:deferred:edit')")
    @Log(title = "延期借据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LoanIouDeferred loanIouDeferred) {
        return toAjax(loanIouDeferredService.updateLoanIouDeferred(loanIouDeferred));
    }

    /**
     * 删除延期借据
     */
    @PreAuthorize("@ss.hasPermi('business:deferred:remove')")
    @Log(title = "延期借据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(loanIouDeferredService.deleteLoanIouDeferredByIds(ids));
    }
}
